// seismic2d.cpp : Defines the entry point for the console application.
//

#include "targetver.h"

#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>

#include "DataLogger.h"
#include "GameTimer.h"
#include "gfx_skitchin.h"
#include "gfx_SDL.h"
#include "FontPrint.h"
//#include "gfx_OpenGL.h"
#include "GameStateManager.h"

GameTimer g_timerLoading;
Skitchin_SDL::CDrawingInterface myInterface;
Skitchin_SDL::CDrawable myDrawable;
Skitchin_SDL::CDrawable dFont;

bool bGameOver = false;
char g_debugOutput[512];
SRect g_rDebugDest = { 0, 0, 320, 240 };


int _tmain(int argc, _TCHAR* argv[])
{
	DataLogger::getInstance()->init(true);
	g_timerLoading.start();

	//Load some stuff
	myInterface.initwindow(1024, 768, 32, "seismic2d Test");
	printf("%ims Loaded window\n", g_timerLoading.getMSElapsed());
	if ( myDrawable.TextureFromFile("test.bmp", ColorRGB( 255, 0, 255)) < 0 )
		bGameOver = true;
	
	create_asciitable( );
	if ( dFont.TextureFromFile( "8x8font.bmp", ColorRGB( 255, 0, 255 ) ) < 0 )
		bGameOver = true; // failed to load sprite, critical failure

	myInterface.fillscreen( ColorRGB( 0, 0, 0 ) );
	myInterface.Tick();

	//End loading
	g_timerLoading.stop();
	printf("%ims Loading complete - entering loop.\n", g_timerLoading.getMSElapsed());

	while( bGameOver == false )
	{
		sprintf( g_debugOutput, "FPS = %i\n", myInterface.GetFPS( ) );
		inputManager.tick( );
		myInterface.fillscreen( ColorRGB( 207, 207, 207 ) );
		myInterface.blit(&myDrawable);
		drawmessage( &myInterface, &dFont, g_rDebugDest, g_debugOutput );
		myInterface.Tick();
		if ( inputManager.isPressed( 0, inputManager.cControllerBack ) )
			bGameOver = true;
	}

	myInterface.destroywindow();
	printf("Game exited main loop.\n");
	system("pause");
	return 0;
}

